package com.fudan.biz.data.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.fudan.es.entity.FieldMeta;
import com.fudan.framework.base.BaseDao;

@Repository
public interface FieldMetaDao extends BaseDao<FieldMeta>{

	@Query(nativeQuery=true,value="delete from t_field_meta where ds_id=?1")
	@Modifying
	public void deleteByDsId(String dsId);

	@Query(nativeQuery=true,value="select * from t_field_meta where ds_id=?1 limit ?2,?3")
	public List<FieldMeta> getFieldsByPage(String dsId,int page,int size);

	@Query(nativeQuery=true,value="select * from t_field_meta where ds_id=?1 and (name like %?2% or alias like %?2%) limit ?3,?4")
	public List<FieldMeta> getFieldsByName(String dsId,String name,int page,int size);
	
	@Query(nativeQuery=true,value="select * from t_field_meta where ds_id=?1 and name=?2")
	public FieldMeta findFieldByName(String dsId,String name);

	@Query(nativeQuery=true,value="select count(*) from t_field_meta where ds_id=?1 and (name like %?2% or alias like %?2%)")
	public Long countFieldsName(String dsId,String name);

	@Query(nativeQuery=true,value="select count(*) from t_field_meta where ds_id=?1")
	public Long countFields(String dsId);

	@Query(nativeQuery=true,value="update t_field_meta set alias=?2 where id=?1")
	@Modifying
	public void updateAlias(String id,String alias);

	@Query(nativeQuery=true,value="select * from t_field_meta where ds_id=?1")
	public List<FieldMeta> getAllFieldByIndex(Object ds_id);
}
